var userDao = {
	tableName : "useraccount",
	findByUsername : function(username) {
		var sql = "select username,pw,timeReg from useraccount where username=:un";
		var ds = this.db().query(sql, "un", username);
		return this.toUserAccount(ds);
	},

	update : function(ua) {
		var sql = "update useraccount set pw=:pw where username=:un";
		this.db().update(sql, "pw", ua.getPassword(), "un", ua.getUsername());
	},

	add : function(ua) {
		var sql = "insert into useraccount(username,pw,timeReg) values(:un,:pw,:timeReg)";
		this.db().update(sql, //
		"pw", ua.getPassword(), "un", ua.getUsername(),//
		"timeReg", ua.getTimeReg());
	},

	// ================
	toUserAccount : function(ds) {
		if (ds.getRowCount() == 0) {
			return null;
		}
		var ua = new UserAccount();
		ua.setUsername(Dt.toString(ds.getCell(0, "username"), null));
		ua.setPassword(Dt.toString(ds.getCell(0, "pw"), null));
		ua.setTimeReg(Dt.toLong(ds.getCell(0, "timeReg"), 0));
		return ua;
	},

	//
	db : function() {
		return getDb("main");
	},

	// ================
	initIfNeed : function() {
		var sql = "create table  if not exists useraccount("//
				+ "username varchar(16) primary key,"//
				+ "pw varchar(16),"//
				+ "timeReg bigint)";
		this.db().update(sql);
	},
};
userDao.initIfNeed();
